numb = int(input())
d = []
m = 0
a = 0
if numb // 1000 > 0 and numb // 1000 < 10:
    numb = str(numb)
    for i in range(len(numb)):
        d.append(numb[i])
    for i in range(4):
        for j in range(4 - i):
            if i == 0:
                a = int(d[j])
            elif i == 1:
                a = int(d[j] + d[j + 1])
            elif i == 2:
                a = int(d[j] + d[j + 1] + d[j + 2])
            elif i == 3:
                a = int(d[j] + d[j + 1] + d[j + 2] + d[j + 3])
            r = a 
            if a == 1:
                r = 0
            elif a > 3:
                for k in range(2, a // 2 + 1):
                    if a % k == 0:
                        r = 0
                        break
            if m < r:
                m = r
    print(m)
else:
    print('0')